﻿
Partial Class WebForm_SearchControl_SearchCleanPlanControl
    Inherits My.MyUserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Visible = False
    End Sub

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.Show()
    End Sub

    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Select" Then
            'Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            'Dim key As DataKey = Me.gv.DataKeys(row.RowIndex)

            Dim rowIndex As Integer = e.CommandArgument

            Me.SelectedPlanID = Me.gv.DataKeys(rowIndex)("PlanID")
            'Me.SelectedPlanID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblPlanID"), Label).Text
            Me.SelectedPlanName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblPlanName"), Label).Text
            Me.UOrganizationID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUOrganizationID"), Label).Text
            RaiseEvent SelectedIndexChanged(Me, New EventArgs)
        End If
    End Sub

    Protected Sub btnShowAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowAll.Click
        Me.BindGV(True)
    End Sub
End Class

Partial Class WebForm_SearchControl_SearchCleanPlanControl
    Public Sub Show()
        Me.BindGV()
    End Sub

    Private Sub BindGV()
        Me.BindGV(False)
    End Sub

    Private Sub BindGV(ByVal showAll As Boolean)
        Dim dat As New clsData
        'Dim sql As New MyUserDataFilter
        Dim sql As MyStringBuilder

        If showAll = True Then
            sql = New MyStringBuilder
        Else
            sql = New MyOrganizationDataFilter
        End If

        sql.Length = 0
        sql.AppendFormat("select cp.*, v.TownName + v.RegionName as VillageName ")
        sql.AppendFormat(" from CleanPlan cp ")
        sql.AppendFormat(" left join Village v on cp.VillageID = v.RegionID ")
        'MyObj.ShowMessage(Me.CanAdmin)
        'MyObj.ShowMessage(clsAuth.GetProgramAuths(Me.ProgramName).Rows(0)("adminaccess"))
        If Me.CanAdmin = False Then
            sql.AppendFormat("where cp.VillageID = '{0}' ", clsAuth.GetUser().RegionID)
        End If

        'sql.AppendFormat(" inner join OrganizationView o on cp.UOrganizationID = o.UOrganizationID ")

        'sql.AppendFormat(Me.GetWhereSQL())

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

        Me.mpSearch.Show()
        Me.Visible = True
    End Sub

    Private Function GetWhereSQL() As String
        Dim sql As New MyStringBuilder

        Return sql.ToString()
    End Function

    Public Property SelectedPlanID() As String
        Get
            Return ViewState("SelectedPlanID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedPlanID") = value
        End Set
    End Property

    Public Property SelectedPlanName() As String
        Get
            Return ViewState("SelectedPlanName")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedPlanName") = value
        End Set
    End Property

    Public Property UOrganizationID() As String
        Get
            Return ViewState("UOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("UOrganizationID") = value
        End Set
    End Property

    Public Event SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Class